# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer:
pkgname=gb
pkgver=0.4.4
_errors_ver=0.8.0
pkgrel=21
pkgdesc="Project based build tool for Go"
options="!check"
url="https://github.com/constabulary/gb"
arch="all"
license="MIT"
makedepends="go"
source="gb-$pkgver.tar.gz::https://github.com/constabulary/gb/archive/v$pkgver.tar.gz
	go-errors-$_errors_ver.tar.gz::https://github.com/pkg/errors/archive/v$_errors_ver.tar.gz
	buildmode-pie.patch
	"
builddir="$srcdir/src/github.com/constabulary/$pkgname"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	mkdir -p ${builddir%/*}
	mv "$srcdir"/$pkgname-$pkgver "$builddir"/
	mkdir -p "$srcdir"/src/github.com/pkg
	mv "$srcdir"/errors-$_errors_ver "$srcdir"/src/github.com/pkg/errors
	default_prepare
}

build() {
	export GOPATH="$srcdir"
	export GO111MODULE=off

	for bin in gb gb-vendor; do
		cd "$builddir"/cmd/$bin && go build -v
	done
}

package() {
	for bin in gb gb-vendor; do
		install -Dm755 "$builddir"/cmd/$bin/$bin \
			"$pkgdir"/usr/bin/$bin
	done
}

sha512sums="d83dd4d80a1126708b0eaa4492eeac9ba772926fdb25a51d80c881db6c0bc6e5edae82f946fd61ae905f689290b4b031698d795006a62a2bcfada8beb535eac4  gb-0.4.4.tar.gz
82055b10c02f13a8ce497388729568ddde7ae61e9fb2592b9acb11c61dfe94d5554432aee168e7c7adbd8345511c3e4ce0ba4c1b23cf253480e199a95316c443  go-errors-0.8.0.tar.gz
38f753d328258d0e1c608aa99c31c080f2fe6a72a1710e78df15e8e47caa54f985b4d13af698c08eb10e0e7615d7848a709dcb7f5c9800ab80ccb34ce1b59a0b  buildmode-pie.patch"
